package com.azt.novel.book.controller;


import com.azt.novel.book.dto.resp.BookInfoRespDto;
import com.azt.novel.book.dto.resp.BookRankRespDto;
import com.azt.novel.book.service.IBookInfoService;
import com.azt.novel.common.resp.RestResp;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.security.NoSuchAlgorithmException;
import java.util.List;


@RestController
@RequestMapping("/api/front/book")
public class BookInfoController {
    @Resource
    private IBookInfoService iBookInfoService;

    /**
     * 小说推荐列表查询接口
     * @param bookId
     * @return
     */
    @Operation(summary = "小说推荐列表查询接口")
    @GetMapping("/rec_list")
    public RestResp<List<BookInfoRespDto>> listRecBooks(@Parameter(description = "小说ID") Long bookId) throws NoSuchAlgorithmException {
        return iBookInfoService.listRecBooks(bookId);
    }

    /**
     * 小说新书榜查询接口
     * @return
     */
    @Operation(summary = "小说新书榜查询接口")
    @GetMapping("/newest_rank")
    public RestResp<List<BookRankRespDto>> listNewestRankBooks(){
        return iBookInfoService.listNewestRankBooks();
    }


    /**
     * 小说新书榜查询接口
     * @return
     */
    @Operation(summary = "小说更新榜查询接口")
    @GetMapping("/update_rank")
    public RestResp<List<BookRankRespDto>> listUpdateRankBooks(){
        return iBookInfoService.listUpdateRankBooks();
    }


    /**
     * 小说点击榜查询接口
     * @return
     */
    @Operation(summary = "小说点击榜查询接口")
    @GetMapping("/visit_rank")
    public RestResp<List<BookRankRespDto>> listVisitRankBooks() {
        return iBookInfoService.listVisitRankBooks();
    }

    /**
     * 小说信息查询接口
     * @param bookId
     * @return
     */
    @Operation(summary = "小说信息查询接口")
    @GetMapping("/{id}")
    public RestResp<BookInfoRespDto> getBookById(
            @Parameter(description = "小说 ID") @PathVariable("id") Long bookId) {
        return iBookInfoService.getBookById(bookId);
    }

    /**
     * 增加小说点击量
     * @param bookId
     * @return
     */
    @Operation(summary = "增加小说点击量")
    @PostMapping("/visit")
    public RestResp<Void> addVisitCount(@Parameter(description = "小说 ID") Long bookId){
        return iBookInfoService.addVisitCount(bookId);
    }

    /**
     * 批量查询小说信息
     */
    @Operation(summary = "批量查询小说信息")
    @PostMapping("/listBookInfoByIds")
    RestResp<List<BookInfoRespDto>> listBookInfoByIds(@RequestBody List<Long> bookIds) {
        return iBookInfoService.listBookInfoByIds(bookIds);
    }
}
